<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/1/28 0028
 * Time: 9:15
 */
namespace app\manager\model\validate;

use think\Validate;

class ManagerValidate extends Validate {
    //public $password_too;
    protected $rule =   [
        'username'  => 'require|max:12|min:5|unique:manager',
        'password' => 'require|max:12|min:6|check_password:两次输入的密码不一致，请核对后再输入',
        //'password_too' => 'require|max:12|min:6',
    ];

    protected $message  =   [
        'username.require'     => '用户名不能为空',
        'username.max'     => '用户名不能超过12个字符',
        'username.min'     => '用户名至少5个字符',
        'username.unique'     => '用户名已经存在',
        'password.require'     => '密码不能为空',
        'password.max'     => '密码不能超过12个字符',
        'password.min'     => '密码至少6个字符',
        //'password_too.require'     => '确认密码不能为空',
        //'password_too.max'     => '确认密码不能超过12个字符',
        //'password_too.min'     => '确认密码至少6个字符',
        //'p_id.require'     => '父级菜单不能为空',
    ];

    protected function check_password($value, $rule, $data) {
        if (empty($data['password'])) {
            return '密码不能为空';
        }
        if ($data['password'] !== $data['password_too']) {
            return $rule;
        }
        return true;
    }

    protected $scene = [
        'add'  =>  ['username','password','password_two'],
        'update'  =>  ['username'],
    ];
}